package com.base.controller;

import java.io.IOException;
import java.text.ParseException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.TaskList;
import com.base.service.LogsService;
import com.base.service.TaskListService;
import com.base.utils.IP;
import com.base.utils.Produce;

/**
 * 添加每日任务信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_TaskList {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private TaskListService taskListService; // 每日任务信息

	// 添加每日任务
	@RequestMapping(value = "/toAddTaskList", method = RequestMethod.POST)
	public @ResponseBody int toAddTaskList(HttpServletRequest request, TaskList taskList)
			throws IOException, ParseException {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
		List<TaskList> btl = taskListService.selectByAll(new TaskList(taskList.getType(), userid)); // 任务信息
		if (btl != null && btl.size() > 0) return -2; // 已添加该任务
		taskList.setId(Produce.getUUID()); // 设置参数 UUID
		taskList.setCreatetime(Produce.getNowDate()); // 创建时间
		taskList.setAgentid(userid); // 代理商ID
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置每日任务信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return taskListService.insertSelective(taskList); // 添加
	}
}
